package com.jlkf.controller;

import java.security.NoSuchAlgorithmException;
import java.util.Map;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jlkf.dao.TblCourseMapper;
import com.jlkf.pojo.TblOrder;
import com.jlkf.service.CourseInfoService;
import com.platform.server.response.response.pojo.ReturnData;
import com.platform.server.util.MD5Util;
import com.platform.server.util.PlatUtils;

@Controller
@RequestMapping("/courseInfo")
public class CourseInfoController extends BaseController{
	
	@Autowired
	private CourseInfoService courseInfoService;
	
	@Autowired
	private TblCourseMapper tblCourseMapper;
	
	/**
	 * 查看课程一级分类
	 */
	@ResponseBody
	@RequestMapping(value = "/selectCourseOneStair",method = RequestMethod.POST)
	public Object selectCourseOneStair(){
		return courseInfoService.selectCourseOneStair();
	}
	
	/**
	 * 查看课程二级跟三级分类
	 */
	@ResponseBody
	@RequestMapping(value = "/selectCourseTwoStair",method = RequestMethod.POST)
	public Object selectCourseTwoStair(Integer id){
		return courseInfoService.selectCourseTwoStair(id);
	}
	
	/**
	 * 查看课程三级分类
	 */
	@ResponseBody
	@RequestMapping(value = "/selectCourseThreeStair",method = RequestMethod.POST)
	public Object selectCourseThreeStair(Integer id){
		return courseInfoService.selectCourseThreeStair(id);
	}
	
	/**
	 * 查看特色课程一级分类
	 */
	@ResponseBody
	@RequestMapping(value = "/selectFeatureCourseOneStair",method = RequestMethod.POST)
	public Object selectFeatureCourseOneStair(){
		return courseInfoService.selectFeatureCourseOneStair();
	}
	
	/**
	 * 查看特色课程二级跟三级分类
	 */
	@ResponseBody
	@RequestMapping(value = "/selectFeatureCourseTwoStair",method = RequestMethod.POST)
	public Object selectFeatureCourseTwoStair(Integer id){
		return courseInfoService.selectFeatureCourseTwoStair(id);
	}
	
	/**
	 * 查看特色课程三级分类
	 */
	@ResponseBody
	@RequestMapping(value = "/selectFeatureCourseThreeStair",method = RequestMethod.POST)
	public Object selectFeatureCourseThreeStair(Integer id){
		return courseInfoService.selectFeatureCourseThreeStair(id);
	}
	
	/**
	 * pc端热搜列表
	 */
	@ResponseBody
	@RequestMapping(value = "/selectTopSearch",method = RequestMethod.POST)
	public Object selectTopSearch(){
		return courseInfoService.selectTopSearch();
	}
	
	 /**
     * 查看课程分类视频列表
     */
	@ResponseBody
	@RequestMapping(value = "/selectCourseSortList",method = RequestMethod.POST)
	public Object selectCourseSortList(Integer one_stair_id,Integer two_stair_id,Integer three_stair_id,Integer difficulty,String type,String param,Integer pageSize, Integer pageNo){
		if ((pageSize == null) || (pageNo == null)){
	      pageNo = Integer.valueOf(1);
	      pageSize = Integer.valueOf(10);
	    }
		return courseInfoService.selectCourseSortList(one_stair_id,two_stair_id,three_stair_id, difficulty, type,param, pageSize, pageNo);
	}
	
	/**
     * pc端搜索课程或老师列表
     */
	@ResponseBody
	@RequestMapping(value = "/searchCourseandTeacher",method = RequestMethod.POST)
	public Object searchCourseandTeacher(String content,Integer difficulty,String type,Integer teacherid,String param,Integer pageSize, Integer pageNo){
		if ((pageSize == null) || (pageNo == null)){
		      pageNo = Integer.valueOf(1);
		      pageSize = Integer.valueOf(10);
		    }
		return courseInfoService.searchCourseandTeacher(content,difficulty,type,teacherid,param,pageSize,pageNo);
	}
	
	/**
     * 课程目录列表
     */
	@ResponseBody
	@RequestMapping(value = "/selectCourseCatalogList",method = RequestMethod.POST)
	public Object selectCourseCatalogList(Integer courseid,Integer userid){
		return courseInfoService.selectCourseCatalogList(courseid,userid);
	}
	
	 /**
     * pc端推荐课程列表
     */
	@ResponseBody
	@RequestMapping(value = "/selectRecommendCourseList",method = RequestMethod.POST)
	public Object selectRecommendCourseList(Integer userid){
		return courseInfoService.selectRecommendCourseList(userid);
	}
	
	/**
     * pc端课程详情
     */
	@ResponseBody
	@RequestMapping(value = "/selectCourseInfo",method = RequestMethod.POST)
	public Object selectCourseInfo(Integer courseid, Integer userid){
		return courseInfoService.selectCourseInfo(courseid,userid);
	}
	
	/**
	 * 确认订单
	 */
	@ResponseBody
	@RequestMapping(value = "/sureOrder",method = RequestMethod.POST)
	public Object sureOrder(Integer userid, Integer courseid,String lessid){
		return courseInfoService.sureOrder(userid,courseid,lessid);
	}
	
	/**
	 * 单个课时确认订单
	 */
	@ResponseBody
	@RequestMapping(value = "/singleSureOrder",method = RequestMethod.POST)
	public Object singleSureOrder(Integer userid,Double money,Integer lessonid){
		return courseInfoService.singleSureOrder(userid,money,lessonid);
	}
	
	
	/**
	 * 确认支付
	 */
	@ResponseBody
	@RequestMapping(value = "/surePay",method = RequestMethod.POST)
	public ReturnData surePay(TblOrder order) {
		return courseInfoService.surePay(order);
	}
	
	/**
	 * pc端微信或支付宝或余额支付课程
	 */
	@ResponseBody
	@RequestMapping(value = "/PcCoursePay",method = RequestMethod.POST)
	public ReturnData PcCoursePay(String orderid, Integer userid,Double money,Integer type,String password)throws Exception {
		return courseInfoService.PcCoursePay(orderid, userid, money,type,password);
	}
	
	/**
	 * app端微信或支付宝或余额支付课程
	 */
	@ResponseBody
	@RequestMapping(value = "/AppCoursePay",method = RequestMethod.POST)
	public ReturnData  AppCoursePay(String orderid, Integer userid, Double money,Integer type,String password,
			String body, String subject,String ip) throws Exception{
		return courseInfoService.AppCoursePay(orderid, userid, money, type, password, body, subject, request.getRemoteAddr());
	}
	
	/**
     * 学习课程视频获得积分与成长值
     */
	@ResponseBody
	@RequestMapping(value = "/insertUserIntegral",method = RequestMethod.POST)
	public ReturnData insertUserIntegral(Integer userid,Integer lessonid,Integer courseid){
		return courseInfoService.insertUserIntegral(userid,lessonid,courseid);
	}
	
	/**
     * 查看课程评价列表
     */
	@ResponseBody
	@RequestMapping(value = "/selectCourseCommentList",method = RequestMethod.POST)
	public ReturnData selectCourseCommentList(Integer courseid,String level){
		return courseInfoService.selectCourseCommentList(courseid,level);
	}
	
	/**
	 * pc发布课程评价
	 */
	@ResponseBody
	@RequestMapping(value = "/insertCourseComment",method = RequestMethod.POST)
	public ReturnData insertCourseComment(Integer course_id,Integer sender_id,String content,String level) throws Exception{
		return courseInfoService.insertCourseComment(course_id, sender_id, content, level);
	}
	
	/**
     * pc端全部作业
     */
	@ResponseBody
	@RequestMapping(value = "/selectPcAllJob",method = RequestMethod.POST)
	public ReturnData selectPcAllJob(Integer courseid){
		return courseInfoService.selectPcAllJob(courseid);
	}
	
	/**
     * 开始学习
     */
	@ResponseBody
	@RequestMapping(value = "/insertLessonStudy",method = RequestMethod.POST)
	public ReturnData insertLessonStudy(Integer userid, Integer courseid, Integer lessonid){
		return courseInfoService.insertLessonStudy(userid, courseid, lessonid);
	}
	
	/**
     * 三大分类列表
     */
	@ResponseBody
	@RequestMapping(value = "/selectBigSortList",method = RequestMethod.POST)
	public ReturnData selectBigSortList(Integer type,Integer param,Integer pageSize, Integer pageNo,Integer userid){
		if ((pageSize == null) || (pageNo == null)){
		      pageNo = Integer.valueOf(1);
		      pageSize = Integer.valueOf(1000);
		    }
		return courseInfoService.selectBigSortList(type,param,pageSize,pageNo,userid);
	}
	
	/**
	 * 查看体系列表详情
	 */
	@ResponseBody
	@RequestMapping(value = "/selectBigSortDetails",method = RequestMethod.POST)
	public ReturnData selectBigSortDetails(Integer type,Integer professionid,Integer userid){
		return courseInfoService.selectBigSortDetails(type,professionid,userid);
	}
	
	/**
	 * APP查看体系列表详情
	 */
	@ResponseBody
	@RequestMapping(value = "/APPselectBigSortDetails",method = RequestMethod.POST)
	public ReturnData APPselectBigSortDetails(Integer type,Integer professionid,Integer userid){
		return courseInfoService.APPselectBigSortDetails(type,professionid,userid);
	}
	
	 /**
     * 学习中心（查看我的课程）
     */
	@ResponseBody
	@RequestMapping(value = "/selectMyCourse",method = RequestMethod.POST)
	public ReturnData selectMyCourse(Integer userid,Integer pageSize, Integer pageNo){
		if ((pageSize == null) || (pageNo == null)){
		      pageNo = Integer.valueOf(1);
		      pageSize = Integer.valueOf(10);
		    }
		return courseInfoService.selectMyCourse(userid,pageSize,pageNo);
	}
	
	/**
     * 学习中心（我的作业）
     */
	@ResponseBody
	@RequestMapping(value = "/selectMyLearningWork",method = RequestMethod.POST)
	public ReturnData selectMyLearningWork(Integer userid){
		return courseInfoService.selectMyLearningWork(userid);
	}
	
	/**
     * 学习中心（我的职业）
     */
	@ResponseBody
	@RequestMapping(value = "/selectMyJobCourse",method = RequestMethod.POST)
	public ReturnData selectMyJobCourse(Integer userid,Integer type,Integer pageSize, Integer pageNo){
		if ((pageSize == null) || (pageNo == null)){
	      pageNo = Integer.valueOf(1);
	      pageSize = Integer.valueOf(10);
	    }
		return courseInfoService.selectMyJobCourse(userid,type,pageSize,pageNo);
	}
	
	 /**
     * 历史记录列表
     */
	@ResponseBody
	@RequestMapping(value = "/selectHistoryRecord",method = RequestMethod.POST)
	public ReturnData selectHistoryRecord(Integer userid){
		return courseInfoService.selectHistoryRecord(userid);
	}
	
	/**
     * 删除历史记录
     */
	@ResponseBody
	@RequestMapping(value = "/deleteHistoryRecord",method = RequestMethod.POST)
	public ReturnData deleteHistoryRecord(Integer userid){
		return courseInfoService.deleteHistoryRecord(userid);
	}
	
	 /**
     * 收藏老师
     */
	@ResponseBody
	@RequestMapping(value = "/collectTeacher",method = RequestMethod.POST)
	public ReturnData collectTeacher(Integer userid, Integer teacherid){
		return courseInfoService.collectTeacher(userid,teacherid);
	}
	
	/**
     * 取消收藏老师
     */
	@ResponseBody
	@RequestMapping(value = "/cancelCollectTeacher",method = RequestMethod.POST)
	public ReturnData cancelCollectTeacher(Integer userid, Integer teacherid){
		return courseInfoService.cancelCollectTeacher(userid,teacherid);
	}
	
	/**
     * 查看特色课程分类视频列表
     */
	@ResponseBody
	@RequestMapping(value = "/selectFeatureCourseSortList",method = RequestMethod.POST)
	public Object selectFeatureCourseSortList(Integer one_stair_id,Integer two_stair_id,Integer three_stair_id,Integer difficulty,String type,Integer pageSize, Integer pageNo,Integer param){
		if ((pageSize == null) || (pageNo == null)){
		      pageNo = Integer.valueOf(1);
		      pageSize = Integer.valueOf(10);
		    }
		return courseInfoService.selectFeatureCourseSortList(one_stair_id,two_stair_id,three_stair_id, difficulty, type,pageSize,pageNo,param);
	}
	
	 /**
     * 我的就业班
     */
	@ResponseBody
	@RequestMapping(value = "/selectMyEmployment",method = RequestMethod.POST)
	public Object selectMyEmployment(Integer userid){
		return courseInfoService.selectMyEmployment(userid);
	}
	
	/**
	 * 更新课程为已分享状态
	 */
	@ResponseBody
	@RequestMapping(value = "/shareCourse",method = RequestMethod.POST)
	public Object shareCourse(Integer courseid){
		return tblCourseMapper.shareCourse(courseid);
	}
	
	/**
     * 根据课程名称自动联想筛选    
     */
	@ResponseBody
	@RequestMapping(value = "/searchCourseAssociate",method = RequestMethod.POST)
	public Object searchCourseAssociate(String courseName){
		return courseInfoService.searchCourseAssociate(courseName);
	}
	
	/**
     * 学习课程获得成长值
     */
	@ResponseBody
	@RequestMapping(value = "/getGrowthValue",method = RequestMethod.POST)
	public Object getGrowthValue(Integer courseid,Integer userid){
		return courseInfoService.getGrowthValue(courseid,userid);
	}
	
	/**
	 * 三大体系确认订单
	 */
	@ResponseBody
	@RequestMapping(value = "/systemSureOrder",method = RequestMethod.POST)
	public Object systemSureOrder(Integer userid, Integer professionid, Integer type){
		return courseInfoService.systemSureOrder(userid,professionid,type);
	}
	
	/**
	 * 三大体系确认支付
	 */
	@ResponseBody
	@RequestMapping(value = "/systemSurePay",method = RequestMethod.POST)
	public ReturnData systemSurePay(TblOrder order) {
		return courseInfoService.systemSurePay(order);
	}
	
	/**
	 * pc支付三大体系课程
	 */
	@ResponseBody
	@RequestMapping(value = "/PcSystemCoursePay",method = RequestMethod.POST)
	public ReturnData PcSystemCoursePay(String orderid, Integer userid,Double money,Integer type,String password)throws Exception {
		return courseInfoService.PcSystemCoursePay(orderid, userid, money,type,password);
	}
	
	/**
	 * app支付三大体系课程
	 */
	@ResponseBody
	@RequestMapping(value = "/AppSystemCoursePay",method = RequestMethod.POST)
	public ReturnData  AppSystemCoursePay(String orderid, Integer userid, Double money,Integer type,
			String body, String subject,String ip) throws Exception{
		return courseInfoService.AppSystemCoursePay(orderid, userid, money, type, body, subject, request.getRemoteAddr());
	}
	
	/**
     * 职业方向列表
     */
	@ResponseBody
	@RequestMapping(value = "/selectJobList",method = RequestMethod.POST)
	public ReturnData  selectJobList(){
		return courseInfoService.selectJobList();
	}

	/**
	 * 线下课程或直播列表
	 */
	@ResponseBody
	@RequestMapping(value = "/getOtherCourseList")
	public ReturnData  getOtherCourseList(Integer type){
		return courseInfoService.getOtherCourseList(type);
	}
	
	/**
	 * 获取活动页面
	 */
	@ResponseBody
	@RequestMapping(value = "/getActivity",method = RequestMethod.POST)
	public ReturnData  getActivity(){
		Map<String, Object> activity = tblCourseMapper.getActivity();
		return new ReturnData(activity,200,"成功"); 
	}
	
	/**
	 * 填写表单
	 */
	@ResponseBody
	@RequestMapping(value = "/insertForm",method = RequestMethod.POST)
	public ReturnData  insertForm(String username,String phone,String school,String grade,String specialty){
		return courseInfoService.insertForm(username, phone, school, grade, specialty);
	}
}	
